package com.family.floor.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.family.common.utils.PageUtils;
import com.family.common.utils.Query;

import com.family.floor.dao.GroupDao;
import com.family.floor.entity.GroupEntity;
import com.family.floor.service.GroupService;


@Service("groupService")
public class GroupServiceImpl extends ServiceImpl<GroupDao, GroupEntity> implements GroupService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<GroupEntity> page = this.page(
                new Query<GroupEntity>().getPage(params),
                new QueryWrapper<GroupEntity>()
        );
        //获取当前系统时间
        List<GroupEntity> records = page.getRecords();
        ArrayList<GroupEntity> entities = new ArrayList<>();
        for (GroupEntity record : records) {
            long currentTimeMillis = System.currentTimeMillis();
            if(currentTimeMillis>record.getStartTime().getTime()==currentTimeMillis<record.getEndTime().getTime()){
                entities.add(record);
            }
        }
        Page<GroupEntity> groupEntityPage = new Page<>();
        groupEntityPage.setRecords(entities);
        groupEntityPage.setTotal(entities.size());
        groupEntityPage.setSize(Integer.parseInt(params.get("limit").toString()));
        return new PageUtils(groupEntityPage);
    }

}